package jdbc.method;

import java.sql.*;

public class JDBCConnection {

    static final String JDBC_DRIVER="com.mysql.cj.jdbc.Driver";
    static final String DB_URL="jdbc:mysql://localhost:3306/mysql?&useSSL=false&serverTimezone=UTC";

    static final String USER="root";
    static final String PASS="123456";

    public static String check(String phoneNumber, String password){
        Connection conn=null;
        Statement stmt=null;

        try{
            Class.forName(JDBC_DRIVER);

            System.out.println("连接数据库");
            conn=DriverManager.getConnection(DB_URL,USER,PASS);
            System.out.println("实例化Statement对象");
            stmt=conn.createStatement();
                    String sql;
            sql="SELECT password FROM accountinformation where PhoneNumber=\""+phoneNumber+"\"";
            ResultSet rs=stmt.executeQuery(sql);
            while(rs.next()){
                String Password=rs.getString("password");

                if(Password.equals(password))
                    return "true";
                else
                    return "false";
            }

            rs.close();
            stmt.close();
            conn.close();

        }catch(SQLException se){
            se.printStackTrace();
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            try{
                if(stmt!=null)stmt.close();
            }catch(SQLException se2){

            }try{
                if(conn!=null)conn.close();
            }catch(SQLException se){
                se.printStackTrace();
            }
        }
        System.out.println("Goodbye!");
        return "not exist";
    }

public static void main(String[] args){
        System.out.println(check("152888506","123"));
}
}
